package com.mo.demo.jsr107;

import org.ehcache.config.CacheRuntimeConfiguration;
import org.ehcache.jsr107.Eh107Configuration;

import javax.cache.*;
import javax.cache.configuration.CompleteConfiguration;
import javax.cache.configuration.MutableConfiguration;
import javax.cache.spi.CachingProvider;

public class Jsr107EhcacheDemo {
    public static void main(String[] args) {
        CachingProvider cachingProvider = Caching.getCachingProvider();
        CacheManager cacheManager = cachingProvider.getCacheManager();
        MutableConfiguration<Long, String> configuration = new MutableConfiguration<>();
        configuration.setTypes(Long.class,String.class);
        // 使用JCache 规范中的MutableConfiguration接口创建 myCache 缓存。
        Cache<Long, String> myCache = cacheManager.createCache("myCache", configuration);
        // 获取 JCache 的CompleteConfiguration
        CompleteConfiguration completeConfiguration = myCache.getConfiguration(CompleteConfiguration.class);
        // 进入连接 Ehcache 和 JCache 的配置桥
        Eh107Configuration eh107Configuration = myCache.getConfiguration(Eh107Configuration.class);
        // 展开为 Ehcache的 CacheRuntimeConfiguration类型
        eh107Configuration.unwrap(CacheRuntimeConfiguration.class);
    }
}
